using System;
using CustomerContactSystem.Core.Infrastructure.Domain;

namespace CustomerContactSystem.Core.Model {
    public class EnquiryDocument : Entity {
        public virtual Enquiry Enquiry { get; set; }
        public virtual DateTime DateAdded { get; set; }
        public virtual User AddedBy { get; set; }
        public virtual string FileName { get; set; }
        public virtual string DocumentName { get; set; }
        public virtual string DocumentDescription { get; set; }
        public virtual string DocumentType { get; set; }

        public virtual string SavePath() {
            var yearMonthFolder = DateAdded.ToString("yyyy/MMMM");
            return "/" + yearMonthFolder + "/";
        }

        protected override void Validate() {
            if (Enquiry == null) {
                AddBrokenRule(new BusinessRule("Enquiry", "Enquiry is required!"));
            }

            if (AddedBy == null || AddedBy.Id == 0) {
                AddBrokenRule(new BusinessRule("AddedBy", "Added by is required!"));
            }

            if (string.IsNullOrEmpty(FileName)) {
                AddBrokenRule(new BusinessRule("FileName", "File name is required!"));
            }

            if (string.IsNullOrEmpty(DocumentName)) {
                AddBrokenRule(new BusinessRule("DocumentName", "Document name is required!"));
            }

            if (string.IsNullOrEmpty(DocumentType))
            {
                AddBrokenRule(new BusinessRule("DocumentType", "Document type is required!"));
            }

            if (DateAdded == DateTime.MinValue)
            {
                AddBrokenRule(new BusinessRule("Added", "Added is required!"));
            }
        }
    }
}